package com.eastedu.superise.handler.question.handler.answer;

import java.util.HashMap;
import java.util.Map;

/**
 * 该类针对T,F特殊处理，因为ran huang 在试题服务中，将T,F当做了判断题选项进行了强制1,0处理，因此遇到选择出现F的情况会判题会出现混乱
 *
 * @author ZhenZhong
 */
public class SpecialForJudgementConverter extends AbstractAsciiConverter implements AsciiConverter {

    private final Map<Integer, Integer> characterintegermap = new HashMap<>();

    {
        characterintegermap.put(84, 1);
        characterintegermap.put(70, 0);
        characterintegermap.put(116, 1);
        characterintegermap.put(102, 0);
        characterintegermap.put(1703952, 1);
        characterintegermap.put(264241, 0);
        characterintegermap.put(448, 1);
        characterintegermap.put(523, 0);
        characterintegermap.put(10004, 1);
        characterintegermap.put(10006, 0);
        characterintegermap.put(65, 0);
        characterintegermap.put(97, 0);
        characterintegermap.put(66, 1);
        characterintegermap.put(98, 1);
    }

    @Override
    public boolean isSupported(String input) {
        int number = stingToNumber(input);
        return characterintegermap.containsKey(number);
    }


    @Override
    protected int doConvert(String input) {
        int number = stingToNumber(input);
        return characterintegermap.get(number);
    }

    @Override
    protected int getCharStartFlag() {
        return 0;
    }

    @Override
    protected int getCharEndFlag() {
        return 0;
    }


    private int stingToNumber(String letter) {
        int length = letter.length();
        int num = 0;
        int number = 0;
        for (int i = 0; i < length; i++) {
            char ch = letter.charAt(i);
            num = (int) (ch);
            number += num;
        }
        return number;
    }
}
